#ifndef GAME_ANIMATION_CLOUD_SHADER_H
#define GAME_ANIMATION_CLOUD_SHADER_H
//
// Game Animation.
// Copyright (C) 2007 Department of Computer Science, University of Copenhagen
//
#include <animation/configuration.h>

#include <OpenTissue/gpu/cg/cg_program.h>
#include <OpenTissue/gpu/image/image.h>
#include <OpenTissue/gpu/image/io/image_read.h>
#include <OpenTissue/gpu/image/io/image_write.h>
#include <OpenTissue/gpu/texture/texture_texture2D.h>
#include <OpenTissue/gpu/image/image_alpha_modulation.h>

namespace animation
{

  /**
   * The Sky Shader Class.
   * Sets up rendering before drawing sky dome geometry.
   */
  class CloudShader
  {
  protected:

    OpenTissue::cg::Program                                      m_vertex_program;
    OpenTissue::cg::Program                                      m_fragment_program;
    boost::shared_ptr<OpenTissue::image::Image<unsigned char> >  m_cloud_image;
    OpenTissue::texture::texture2D_pointer                       m_cloud_textures;
  public:
	  CloudShader(){

		
	  }
	  bool loadFragmentShader(){
		  //--- Load textures if they are not allready loaded
		  if(!m_cloud_image){
			  m_cloud_image.reset( new OpenTissue::image::Image<unsigned char>() );
			  OpenTissue::image::read(demo_path + "TheSwampThing2008/data/cloud_texture.png",*m_cloud_image);
			  m_cloud_textures = m_cloud_image->create_texture(GL_RGBA);
			  m_cloud_textures->set_repeating(true);
			  m_cloud_textures->set_mipmapping(true);
		  }	
		  if(!m_fragment_program.is_program_loaded()){
			  if(!m_fragment_program.load_from_file(OpenTissue::cg::Program::fragment_program,demo_path + "../animation/fp_cloud.cg")){
				  return false;
			  }
		  }
		  m_fragment_program.set_input_texture("cloud_texture",m_cloud_textures);
		  return true;
	  }

    bool pre_render ( ){

		if(!m_vertex_program.is_program_loaded()){
			if(!m_vertex_program.load_from_file(OpenTissue::cg::Program::vertex_program,demo_path + "../animation/vp_cloud.cg")){
				return false;
			}
		}
		m_vertex_program.set_modelview_projection_matrix();
		
		//--- load fragment program

		m_fragment_program.enable();
		m_vertex_program.enable();
		return true;
	}


    void post_render()
    {
      m_fragment_program.disable();
      m_vertex_program.disable();
    }
  };

} // namespace animation

// GAME_ANIMATION_SKY_SHADER_H
#endif
